package br.com.caelum.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.caelum.jdbc.controle.LoginControl;

/**
 * Servlet implementation class LoginServlet
 */

@WebServlet("/loginServlet")
public class LoginServlet extends HttpServlet {
	

	/**
	 * 
	 */
	
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String usuario = request.getParameter("usuario");
            String senha = request.getParameter("senha");
            LoginControl lc = new LoginControl();
            if(lc.isAutentic(usuario, senha)){
            	request.getRequestDispatcher("adiciona-contato.html").forward(request, response);
            }else{
            	request.getRequestDispatcher("index.html").forward(request, response); 
            	}
        } finally {
            out.close();
}
}
	}




